package com.by.toolkit.model;

import com.by.toolkit.consts.GlobalConst;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 分页统一响应参数
 *
 * @author YanBingHao
 * @since 2023/12/27
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageResp<T> implements Serializable {

    private Long totalSize;

    private List<T> datas;

    public static <T> PageResp<T> ofNull(){
        return PageResp.of(GlobalConst.ZERO_LONG, Collections.emptyList());
    }

    public static <T> PageResp<T> of(Long totalSize, List<T> datas){
        PageResp<T> ret = new PageResp<>();
        ret.setTotalSize(totalSize);
        ret.setDatas(datas);
        return ret;
    }

}
